package com.zygh.policeasset.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.AssetsSteps;
import com.zygh.policeasset.pojo.AssetsStepsProcess;
import com.zygh.policeasset.service.AssetsStepsProcessService;
import com.zygh.policeasset.service.AssetsStepsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/assetssteps"})
@Api(tags = {"资产审批审批流程主表"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/AssetsStepsController.class */
public class AssetsStepsController {
    @Autowired
    AssetsStepsService assetsStepsService;
    @Autowired
    AssetsStepsProcessService assetsStepsProcessService;

    @RequestMapping(value = {"/"}, method = {RequestMethod.GET})
    @ApiOperation("获取资产审批审批流程分页列表")
    public Object findAll(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam("status") Integer status) {
        return this.assetsStepsService.queryAll(pageNum, pageSize, status);
    }

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加")
    public Object add(@RequestBody AssetsSteps assetsSteps) {
        if (StrUtil.isEmpty(assetsSteps.getStepsType())) {
            return new CommonResult().validateFailed("审批类型为空");
        }
        if (this.assetsStepsService.queryByType(assetsSteps.getStepsType()) > 0) {
            return new CommonResult().validateFailed("已录入有该类型的审批流程");
        }
        if (this.assetsStepsService.add(assetsSteps) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加错误");
    }

    @RequestMapping(value = {"/remove"}, method = {RequestMethod.GET})
    @ApiImplicitParam(name = "id", value = "唯一主键", required = true, paramType = "query")
    @ApiOperation("删除")
    public Object delete(Integer id) {
        if (StrUtil.isEmpty(String.valueOf(id))) {
            return new CommonResult().validateFailed("id不能为空");
        }
        if (this.assetsStepsService.deleteById(id) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除失败");
    }

    @RequestMapping(value = {"/selectbyid"}, method = {RequestMethod.GET})
    @ApiImplicitParam(name = "id", value = "唯一主键", required = true, paramType = "query")
    @ApiOperation("通过ID查询")
    public Object selectById(Integer id) {
        if (StrUtil.isEmpty(String.valueOf(id))) {
            return new CommonResult().validateFailed("id不能为空");
        }
        return new CommonResult().success(this.assetsStepsService.queryById(id));
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("更新")
    public Object update(@RequestBody AssetsSteps assetsSteps) {
        if (this.assetsStepsService.update(assetsSteps) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("更新失败");
    }

    @RequestMapping(value = {"/updatebyid"}, method = {RequestMethod.GET})
    @ApiOperation("修改状态")
    public Object updateByid(@RequestParam("id") Integer id, @RequestParam("status") Integer status, @RequestParam("userId") Integer userId, @RequestParam("opinion") String opinion, @RequestParam("type") String type) {
        int count = this.assetsStepsService.updateByid(id, status);
        AssetsStepsProcess assetsStepsProcess = new AssetsStepsProcess();
        assetsStepsProcess.setAssetsStepsId(id);
        assetsStepsProcess.setDoTime(DateUtil.now());
        assetsStepsProcess.setUserId(userId);
        assetsStepsProcess.setOpinion(opinion);
        assetsStepsProcess.setStatus(status);
        assetsStepsProcess.setType(type);
        this.assetsStepsProcessService.add(assetsStepsProcess);
        if (count > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("更新失败");
    }
}